<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%
    String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>电子发票申请</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">

<div class="Wrapper">
    <div>
        <div id="pageInTab" class="pageInTab">
            <form id="cust_elecInvoice_add_form">
                <div class="fieldBox col_100" style="display:none;">
                    <div class="field">
                        <input name="cstId" id="cstId" type="text" class="ui-textbox" value="${cstId}">
                        <input name="billWayCd" id="billWayCd" type="text" class="ui-textbox" value="${flag}">
                        <input name="prjId" id="prjId" type="text" class="ui-textbox" value="">
                        <input name="lsCntNo" id="lsCntNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldset1 tabel_col clearFix">
                    <div class="fieldBox col_33">
                        <div class="label">客户名称</div>
                        <div class="field">
                            <input name="cstNm" id="cstNm" disabled type="text" class="ui-textbox" value="${cstNm }">
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">项目所属机构</div>
                        <div class="field">
                            <input name="orgNm" id="orgNm" disabled="disabled" type="text" class="ui-textbox" value="${orgCdNm }"/>
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">发票流水号</div>
                        <div class="field">
                            <input name="serialNum" id="serialNum" type="text" class="ui-textbox" value="" disabled/>
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">客户类型</div>
                        <div class="field">
                            <input name="cstTypNm" id="cstTypNm" type="text" class="ui-textbox" value="${cstTypNm}" disabled/>
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">申请人</div>
                        <div class="field">
                            <input name="applyNm" id="applyNm" type="text" class="ui-textbox" value="${applyNm}" disabled/>
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">开票方式</div>
                        <div class="field">
                            <input name="applyCd" id="applyCd" type="text" class="ui-textbox" value="电子发票" disabled/>
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">版本文件下载地址</div>
                        <div class="field">
                            <input name="downloadUrl" id="downloadUrl" type="text" class="ui-textbox" value="" disabled/>
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">发票抬头</div>
                        <div class="field">
                            <input name="invTitle" id="invTitle" disabled="disabled" type="text" class="ui-textbox" value="${cstNm }"/>
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">纳税人识别号</div>
                        <div class="field">
                            <input name="invTaxId" id="invTaxId" type="text" class="ui-textbox" value="" placeholder="" validate="{stringMaxLength:60}"/>
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">联系电话<span class="requiredSymbol">*</span></div>
                        <div class="field">
                            <input name="invTel" id="invTel" type="text" class="ui-textbox" value="" placeholder="联系电话" validate="{required:true,stringMaxLength:30}"/>
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">电子邮箱<span class="requiredSymbol">*</span></div>
                        <div class="field">
                            <input name="email" id="email" type="text" class="ui-textbox" value="" placeholder="购方电子邮箱" validate="{required:true,stringMaxLength:60}"/>
                        </div>
                    </div>
                </div>
            </form>
            <!-- 支付表列表 -->
            <jsp:include page="invoiceApplyGrid.jsp" flush="true"></jsp:include>
        </div>
    </div>
</div>

<script>
    var grid;
    var cstTypCd = '${cstTypCd}';

    $(function () {
        $("#cust_elecInvoice_add_form").ligerForm({
            validate: true
        });

        if ("2" == cstTypCd) {
            var formSet = liger.get("cust_elecInvoice_add_form");
            formSet.setFieldValidate("invTaxId", {required: true, stringMaxLength: 60}, {required: '客户为法人时，纳税人识别号必填！'});
        }
    });

    // 保存
    function applyElecInv() {
        var ligerForm = liger.get("cust_elecInvoice_add_form");
        if (!ligerForm.valid()) {
            top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
            return false;
        }
        var ligerForm = liger.get("cust_elecInvoice_add_form");
        //验证通过后获取数据
        var formData = ligerForm.getData();

        var _grid = grid.getSelectedRows();
        if(_grid.length == 0){
            top.$.ligerDialog.SQalert({content: "请选择需要开票的费用项数据！", SQ_type: "warning"});
            return false;
        }
        formData["paySchFeeList"] = JSON.stringify(_grid);

        var url = '<%=path%>/invoice/electron/apply.do';
        $.ligerDialog.confirm("确认开具电子发票吗?", function (flag) {
            if (flag == false) return;
            AjaxUtils.ajaxPost(url, formData, function(msg){
                if (msg.success == 1) {
                    $.ligerDialog.SQalert({content: msg.info, SQ_showButtons: true, SQ_type: "info",
                        onClose: function () {
                            Remove_navTab();
                            frameElement.dialog.close();
                        }
                    });
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_showButtons: true, SQ_type: "error"});
                }
            }, true);
        });
    }
</script>

</body>
</html>